import 'package:flutter/material.dart';
import '../home/home_page.dart';
import '../category/category_page.dart';
import '../cart/cart_page.dart';
import '../profile/profile_page.dart';
import '../chat/chat_page.dart';

class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  int _currentIndex = 2;
  bool _showBottomNav = false;
  
  
  final List<String> _pageTitles = [
    '首页',
    '分类',
    '聊天',
    '购物车',
    '我的',
  ];

  final List<Widget> _pages = [
    const HomePage(),
    const CategoryPage(),
    const ChatPage(),
    const CartPage(),
    const ProfilePage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: const Icon(Icons.menu),
          onPressed: () {
            setState(() {
              _showBottomNav = !_showBottomNav;
            });
          },
        ),
        title: Text(_pageTitles[_currentIndex]),
      ),
      body: _pages[_currentIndex],
      bottomNavigationBar: _showBottomNav ? BottomNavigationBar(
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        selectedItemColor: Theme.of(context).primaryColor,
        unselectedItemColor: Colors.grey,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: '首页',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.category),
            label: '分类',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.chat),
            label: '聊天',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.shopping_cart),
            label: '购物车',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.person),
            label: '我的',
          ),
        ],
      ) : null,
    );
  }
} 